{* $Id$ *}
{include_core file="admin/lib/header.html" title="用户展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">用户管理<span>在这里对用户进行管理</span></h2>
    <a href="{AnUrl('user/admin/add')}" class="btn btn-success btn-sm right"><i class="icon-add"></i>添加用户</a>
  </div>
  {*<div class="search-level1 clearfix" {if $is_advenced == 1}style="display:none;"{/if}>
    <form action="user/admin" method="get" {if $is_advenced == 0}style="display:none;"{/if}>
      <input type="hidden" name="is_advenced" value="0">
      <input type="hidden" name="status" value="{$status}">
      <input type="text" class="left" name="search_filter[user_name]" value="{$search_filter.user_name}">
      <button type="submit" class="btn btn-success btn-sm left">搜索</button>
      <a href="javascript:void(0);" class="close js_advanced {if $is_advenced == 1}js_isOpen open{/if}">高级搜索<em></em></a>
    </form>
  </div> *}
  <div class="search-form js_advancedForm" >
    <form action="user/admin" method="get" class="js_focusSearchForm">
      <input type="hidden" name="is_advenced" value="1">
      <input type="hidden" name="status" value="{$status}">
      <p>
        <label for="" class="search-f-label">手机号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[user_name]" value="{$search_filter.user_name}">
      </p>
      <p>
        <label for="" class="search-f-label">姓名：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[realname]" value="{$search_filter.realname}">
      </p>
      <p class="js_roleChange">
        <label for="" class="search-f-label">角色：</label>
          <select name="search_filter[role_id]" class="search-f-slt1">
            <option value="0">全部</option>
            <option value="{user_config::AGENCY}" {if $search_filter.role_id == user_config::AGENCY}selected{/if} >合伙人</option>
            <option value="{user_config::MARKETING}" {if $search_filter.role_id == user_config::MARKETING}selected{/if} >市场人员</option>
            <option value="{user_config::STORE_OWNER}" {if $search_filter.role_id == user_config::STORE_OWNER}selected{/if} >总店店长</option>
            <option value="{user_config::STORE_MANAGER}" {if $search_filter.role_id == user_config::STORE_MANAGER}selected{/if} >分店店长</option>
            <option value="{user_config::ASSISTANT}" {if $search_filter.role_id == user_config::ASSISTANT}selected{/if} >助理</option>
            <option value="{user_config::FINANCIAL_MANAGEMENT}" {if $search_filter.role_id == user_config::FINANCIAL_MANAGEMENT}selected{/if} >财务</option>
            <option value="{user_config::CINEMA_ASSISTANT}" {if $search_filter.role_id == user_config::CINEMA_ASSISTANT}selected{/if} >影院专员</option>
            <option value="{user_config::CINEMA_MANAGER}" {if $search_filter.role_id == user_config::CINEMA_MANAGER}selected{/if} >院线专员</option>
            <option value="{user_config::AREA_MANAGER}" {if $search_filter.role_id == user_config::AREA_MANAGER}selected{/if} >大区经理</option>
            <option value="{user_config::DIRECTOR}" {if $search_filter.role_id == user_config::DIRECTOR}selected{/if} >总监</option>
            
         </select>
      </p>
      <p class="js_assistant" style="display:none">
        <label for="" class="search-f-label">选择助理：</label>
          <select name="assistant_user_id" class="search-f-slt1">
            <option value="0">请选择助理</option>
            {if $assistant_list}
              {foreach $assistant_list as $k=>$v}
                <option value="{$v.id}" {if $assistant_user_id == $v.id}selected{/if} >{$v.realname}------{$v.mobile}</option>
              {/foreach}
            {/if}
         </select>
      </p>
      <p>
      <label for="" class="search-f-label">注册时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>
  
  <!--start:列表-->
  <table class="list-table">
    <caption style="margin-bottom:25px;">
      <span style="margin-bottom:5px;">按状态：
        <a href='{AnUrl("user/admin?status=1&dealer_level=$dealer_level&only_dealer=0")}' {if $status == 1} class="label label-primary" {else} class="label label-default" {/if}>正常</a>
        <a href='{AnUrl("user/admin?status=0&dealer_level=$dealer_level&only_dealer=0")}' {if $status == 0} class="label label-primary" {else} class="label label-default" {/if}>已禁用</a>
      </span><br/>
      <span>按条件：
        <a href='{AnUrl("user/admin?status=$status&dealer_level=-1&only_dealer=1")}' {if $dealer_level == -1 && $only_dealer == 1} class="label label-primary" {else} class="label label-default" {/if}>只看合伙人</a>
        <a href='{AnUrl("user/admin?status=$status&dealer_level=1&only_dealer=1")}' {if $dealer_level == 1} class="label label-primary" {else} class="label label-default" {/if}>一级合伙人</a>
        <a href='{AnUrl("user/admin?status=$status&dealer_level=2&only_dealer=1")}' {if $dealer_level == 2} class="label label-primary" {else} class="label label-default" {/if}>二级合伙人</a>
        <a href='{AnUrl("user/admin?status=$status&role_id=34")}' {if $role_id == 34} class="label label-primary" {else} class="label label-default" {/if}>影院专员</a>
        <a href='{AnUrl("user/admin?status=$status&role_id=33")}' {if $role_id == 33} class="label label-primary" {else} class="label label-default" {/if}>大区经理</a>
        <a href='{AnUrl("user/admin?status=$status&role_id=32")}' {if $role_id == 32} class="label label-primary" {else} class="label label-default" {/if}>总监</a>
        <a href='{AnUrl("user/admin?status=$status&role_id=35")}' {if $role_id == 35} class="label label-primary" {else} class="label label-default" {/if}>院线专员</a>
        
        
      </span>
    </caption>
    <thead><tr>
      {if $status == 1}
      <th style="width:20px;"><input type="checkbox" class="selectAll"></th>
      {/if}
      <th style="width:60px;">编号</th>
      <th style="width:60px;">用户名</th>
      <th style="width:60px;">角色</th>
      <!-- <th style="width:60px;">头像</th> -->
      <th style="min-width:300px;">其他信息</th>
      <th style="width:130px;">注册时间</th>
      {if $status == 1}
      <th>积分/抱抱币数</th>
      <th>积分/抱抱币操作</th>
      {/if}
      <th style="width:60px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $user_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          {if $status == 1}
          {if $v.id == 1}
            <td></td>
          {else}
            <td><input type="checkbox" class="listSelect"></td>
          {/if}
          {/if}
          <td class="js_userName">{$v.id}</td>
          <td class="js_userName">{$v.user_name}</td>
          <td>{$v.role_type}</td>
          <!-- <td>
              <img width="60" src="{user_helper::avatar($v['id'])}">
          </td> -->
          <td>
    {if $v.parent_id > 0}父级合伙人:{$v.parent_user_name}<br/>{/if}
            {* 性别：{if $v.gender == 1}男{elseif $v.gender == 0}女{else}未知{/if}<br /> *}
            手机号码：{$v.mobile}<br />
            真实姓名：{$v.realname}
          </td>
          <td>{time_format($v.add_time)}</td>
          {if $status == 1}
          <td>{$v.score}/{$v.bbcoin}</td>
          <td>
            <a href="{AnUrl("score_record/admin/add_score?id={$v.id}&query_string={$query_string}")}" class="btn btn-warning btn-xs"><i class="icon-edit icon-white"></i>增加积分</a>
            <a href="{AnUrl("bbcoin/admin/add_bbcoin?id={$v.id}&query_string={$query_string}")}" class="btn btn-success btn-xs"><i class="icon-edit icon-white"></i>增加抱抱币</a>
          </td>
          {/if}
          <td>
            <a id="{$v.role_id}"  
            {if $v.role_id == user_config::CINEMA_MANAGER}
            {* 院线管理员 *}
                href="{AnUrl("user/admin/cinema_manager/add&id={$v.id}&query_string={$query_string}")}"
            {elseif $v.role_id == user_config::CINEMA_ASSISTANT }
            {* 影院专员 *}
                 href="{AnUrl("user/admin/cinema_assistant/add&id={$v.id}&query_string={$query_string}")}"
            {elseif $v.role_id == user_config::AREA_MANAGER }
            {* 大区经理 *}
                href="{AnUrl("user/admin/area_manager/add&id={$v.id}&query_string={$query_string}")}"
            {elseif $v.role_id == user_config::DIRECTOR}
            {* 总监 *}
                href="{AnUrl("user/admin/director/add&id={$v.id}&query_string={$query_string}")}"
            {else}
                href="{AnUrl("user/admin/edit?id={$v.id}&query_string={$query_string}")}"
            {/if}
            
            class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
<!--             <a href="{AnUrl("user/admin/edit?id={$v.id}&status={$status}&search_filter[role_id]={$search_filter.role_id}&search_filter[realname]={$search_filter.realname}&search_filter[assistant_user_id]={$search_filter.assistant_user_id}&search_filter[user_name]=&{$search_filter.user_name}&dealer_level={$dealer_level}&only_dealer={$only_dealer}&search_filter[start_time]={$search_filter.start_time}&search_filter[end_time]={$search_filter.end_time}&is_advenced={$is_advenced}&page_no={$page_no}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a> -->
            {if $status == 1 && $v.id != 1}
              {if $v.parent_id == 0 && $v.dealer_level == 1}
                <a href="{AnUrl("user/admin/add_second_dealer?id={$v.id}&query_string={$query_string}")}" class="btn btn-success btn-xs"><i class="icon-edit icon-white"></i>增加二级合伙人</a>
                <a url="{AnUrl("user/admin/get_second_dealer_list?id={$v.id}&query_string={$query_string}")}" class="btn btn-primary btn-xs js_showSecondDealer"><i class="icon-edit icon-white"></i>查看子合伙人</a>
              {/if}
              {if $v.dealer_level >= 1}
                <a href="{AnUrl("user/admin/show_area_list?id={$v.id}&query_string={$query_string}")}" class="btn btn-primary btn-xs"><i class="icon-edit icon-white"></i>设置/查看地区</a>
                <a href="{AnUrl("user/admin/show_dealer_address_list?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>设置/查看仓库地址</a>
              {/if}
              <a href="{AnUrl("user/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs deleteOne"><i class="icon-trash icon-white"></i>禁用</a>
            {elseif $status == 0}
              <a href="{AnUrl("user/admin/change_status?status=1")}" class="btn btn-success btn-xs changeStatus"><i class="icon-trash icon-white"></i>恢复</a>
              <a href="{AnUrl("user/admin/delete_user?id={$v.id}")}" class="btn btn-danger btn-xs deleteOneUser"><i class="icon-trash icon-white"></i>删除</a>
            {/if}
          </td>
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot><tr><td><input type="checkbox" class="selectAll"></td><td colspan="6"><a href="{AnUrl("user/admin/delete")}" class="btn btn-danger btn-xs deleteAll">批量禁用</a></td></tr></tfoot>
    {/if}
  </table>
  <script type="text/javascript">
  
  $(function(){
      
      
      if ('{user_config::AGENCY}' == $('select[name="search_filter[role_id]"]').val()) {
          $('.js_assistant').show();
      } else {
          $('.js_assistant').hide();
          $('select[name="assistant_user_id"]').val('0');
      }
      
      $('select[name="search_filter[role_id]"]').change(function(){
          if ('{user_config::AGENCY}' == $(this).val()) {
              $('.js_assistant').show();
          } else {
              $('.js_assistant').hide();
              $('select[name="assistant_user_id"]').val('0');
          }
      });
      
      
   // 将制定的元素设置为可是区域居中
      function center_format(obj){
          // 获取可是窗口的宽度
          var winWidth  = $(window).width();
          var winHeight = $(window).height();
          
          // 计算窗体本身的宽和高
          var objWidth = obj.width();
          var objHeight = obj.height();
          
          // 设置窗体的位置
          obj.css('position', 'fixed');
          // 计算left和top值
          var objLeft = (winWidth - objWidth)/2;
          var objTop = (winHeight - objHeight)/3; // 如果除以2感觉不垂直居中
          obj.css('left', objLeft+'px');
          obj.css('top', objTop+'px');
          
      }
      
    // 高级搜索
    $('.js_advanced').click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var outBox  = thisObj.closest('form');
      if (thisObj.hasClass('js_isOpen')) {
        thisObj.removeClass('js_isOpen open');
        outBox.find('input').show();
        outBox.find('button').show();
        $('.js_advancedForm').hide();
      } else {
        thisObj.addClass('js_isOpen open');
        outBox.find('input').hide();
        outBox.find('button').hide();
        $('.js_advancedForm').show();
      }
    });
    
    // 查看子合伙人
    $('.js_showSecondDealer').click(function(){
        // 获取此一级合伙人的id
        var $url = $(this).attr('url');
        var th = $(this);
        // 发送ajax查询子合伙人
        $.ajax({
            url : $url,
            type : "get",
            dataType : 'json',
            error : function () {
              showMsg('此合伙人没有二级合伙人!');
            },
            success : function(res){
                if (res != 'no') {
                    var infoList = res;
                    $('.float-bg').show();
                    var list = $('.js_secondDealerList').clone(true, true);
                    list.find('.js_dealerTitle').html(th.parents('tr').find('td.js_userName').html()+'的子合伙人信息');
                    $('body').append(list);

                    // 设置弹窗的位置
                    center_format(list);
                    list.show();
                    
                    // 说明 存在二级合伙人
                    for (var i in infoList) {
                        var info = $('<tr><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]["user_name"]+'</td><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]["mobile"]+'</td></tr>');
                        list.find('.js_expressTable').append(info);
                    }
                    
                    list.find('.js_closeDealerList').click(function(){
                        list.hide();
                        list.remove();
                        $('.float-bg').hide();
                    });
                    
                } else {
                    alert('此合伙人没有二级合伙人!');
                }
            }
        });
        
        return false;
    });
    
  });
  

  
  </script>
<div class="float-confirm js_secondDealerList" style="z-index: 20000;display: none; width:auto; height:auto; margin:0px; position : fixed;">
  <div class="float-confirm-con" style="margin:0px 0px;">
    <a class="icon-close js_closeDealerList" href="javascript:void(0);">关闭</a>
    <p style="font-size:18px;color:#23a18b;" class="js_dealerTitle">子合伙人信息</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;max-height:400px;over-flow:hidden;margin-bottom:15px;">
      <table style="line-height:50px;border:1px solid #ccc;margin:0 auto;" class="js_expressTable">
        <tr>
          <th style="width:200px;text-align:center;border:1px solid #ccc">用户名</th>
          <th style="width:200px;text-align:center;border:1px solid #ccc">手机号码</th>
        </tr>
        
      </table>
      <table style="line-height:50px;display:none;width:400px;line-height:24px;" class="js_refundTable">
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
  </div>
</div>
<div class="float-bg" style="z-index: 19999; display: none"></div>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
{include_core file="admin/lib/footer.html"}